//
//  NSLayoutConstraint+XibScreenAdapter.m
//  鲸心
//
//  Created by 陶正亮 on 2020/2/11.
//  Copyright © 2020 陶正亮. All rights reserved.
//

#import "NSLayoutConstraint+XibScreenAdapter.h"
#import "BusinessHeader.h"
static char adapterSizeKey;
static char adapterBySelfKey;


@implementation NSLayoutConstraint (XibScreenAdapter)
- (void)setAdapterScreen:(BOOL)adapterScreen
{
    if (adapterScreen) {
        self.constant = round(self.constant * Scale());
    }
}

- (BOOL)adapterScreen
{
    return YES;
}

- (void)setAllAdapterScreen:(BOOL)allAdapterScreen
{
    if (allAdapterScreen) {
        if (self.adapterSize == 0) {
            self.adapterSize = self.constant;
        }
        self.constant = round(self.adapterSize * Scale());
    }
}

- (BOOL)allAdapterScreen
{
    return YES;
}
- (void)setAdapterSize:(CGFloat)adapterSize {
    objc_setAssociatedObject(self, &adapterSizeKey, [NSNumber numberWithFloat:adapterSize], OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (CGFloat)adapterSize {
    NSNumber * number = objc_getAssociatedObject(self, &adapterSizeKey);
    return number.floatValue;
}

@end
